// 配置路由相关信息
import Vue from "vue";
import VueRouter from "vue-router";

// import Home from "../components/Home";
// import About from "../components/About";
// import User from "../components/User";

const Home = () => import("../components/Home");
const HomeNews = () => import("../components/HomeNews");
const HomeMessages = () => import("../components/HomeMessage");

const About = () => import("../components/About");
const User = () => import("../components/User");
const Profile = () => import("../components/Profile")

Vue.use(VueRouter);

const routes = [
  {
    path: '',
    redirect: 'home'
  },
  {
    path: '/home',
    component: Home,
    meta: {
      title: '首页'
    },
    // children里的path不加/
    children: [
      // {
      //   path: '',
      //   redirect: 'news'
      // },
      {
        path: 'news',
        component: HomeNews
      },
      {
        path: 'messages',
        component: HomeMessages
      }
    ]
  },
  {
    path: '/about',
    component: About,
    meta: {
      title: '关于'
    },
  },
  {
    path: '/user/:userId?',
    component: User,
    meta: {
      title: '用户'
    },
  },
  {
    path: '/profile',
    component: Profile,
    meta: {
      title: '档案'
    },
  }
];

const router = new VueRouter({
  // 配置路径和组件之间的映射关系
  routes,
  mode: 'history',
  linkActiveClass: 'active'
});

router.beforeEach((to, from, next) => {
  // 从from跳转到to
  document.title = to.matched[0].meta.title;
  next();
});

// router.afterEach((to, from) => {
   
// });



export default router